home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / Moofwars 1.02 / MoofWars Sprocket / •Headers / TTileCollection.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-05  |  6.2 KB  |  158 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. TTileCollection.h
  4.  
  5. #     A TileCollection is a set of tiles that can be used to draw a grid.  Essentially,
  6. #   this class performs the same function that the TGraphicCollection class does, but
  7. #   it is designed just to draw 32x32x8 tiles.  By making this code as specific as
  8. #   possible, this code is more than twice as fast as using TGraphics to draw the tiles.
  9. #
  10. Author: Timothy Carroll
  11. Apple Developer Technical Support
  12. timc@apple.com
  13. #
  14. Modification History: 
  15. #
  16. 8/15/96        TMC     Initial Release
  17. #
  18. Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  19. #
  20. #
  21. You may incorporate this sample code into your applications without
  22. restriction, though the sample code has been provided "AS IS" and the
  23. responsibility for its operation is 100% yours.  However, what you are
  24. not permitted to do is to redistribute the source as "DSC Sample Code"
  25. after having made changes. If you're going to re-distribute the source,
  26. we require that you make it clear in the source that the code was
  27. descended from Apple Sample Code, but that you've made changes.
  28. #
  29. *************************************************************************************/
  30.  
  31.  
  32. #ifndef _TTILECOLLECTION_
  33. #define _TTILECOLLECTION_
  34.  
  35. #pragma once
  36.  
  37. #if PRAGMA_STRUCT_ALIGN
  38. #pragma options align=power
  39. #endif
  40.  
  41. // To provide an smaller, simpler interface, we'll define a couple of macros here.
  42.  
  43. #define NewTileCollection(resID) TTileCollection::NewCollection((resID))
  44. #define DisposeTileCollection(collection) (collection)->DisposeReference()
  45.  
  46.  
  47.  
  48.  
  49. class TTileCollection
  50. {
  51.     public:
  52. /*************************************************************************************
  53.     Static Creator and Reference Counting
  54.     
  55.     These are the routines that handle the actual creation of the objects, along with reference
  56.     counting and so on.  You shouldn't need to call the reference counting routines yourself --
  57.     instead, call the macros to create and destroy collections and they'll do the right thing.
  58.     
  59.     Note that DisposeReference is the routine actually responsible for destroying a collection
  60.     when we're through.
  61.     
  62.     A TTileCollection is loaded from a resource of type 'TILE'.
  63. *************************************************************************************/
  64.     static TTileCollection     *NewCollection (SInt16 resID);
  65.  
  66.     void    AddReference (void);
  67.     void    DisposeReference (void);    
  68.     
  69. /*************************************************************************************
  70.     Locking and Unlocking
  71.     
  72.     You are never required to lock a collection -- the routines run fine either way.
  73.     The functions are provided because we mainly use these functions to draw grids for
  74.     games, where all of the graphics are loaded ahead of time and stick around until
  75.     the game ends.  By locking the collections, we ensure that they won't be moving around
  76.     while the game is actually running.
  77. *************************************************************************************/
  78.     OSErr    LockCollection (void);
  79.     OSErr    UnlockCollection (void);
  80.     
  81.     
  82. /*************************************************************************************
  83.     Creating and destroying the collection
  84.     
  85.     The actual work to create and destroy the collection is done by the following two routines.
  86.     CreateCollection loads the resource and sets up all the required data, destroy collection
  87.     disposes of any memory allocated by the object.
  88.  
  89. *************************************************************************************/
  90.     OSErr    CreateCollection (void);
  91.     OSErr    DestroyCollection (void);
  92.     
  93.     
  94. /*************************************************************************************
  95.     Accessor Functions
  96.     
  97.     We define only one accessor function, which is used to return the resource ID of the loaded
  98.     collection.
  99.     
  100. *************************************************************************************/
  101.     SInt16            GetResID(void) {return fResID;}
  102.     
  103.     
  104. /*************************************************************************************
  105.     Utility Functions
  106.     
  107.     The main routines that TTile is known for.  I won't explain them in detail here, check out
  108.     the TTile class for details.
  109. *************************************************************************************/
  110.  
  111.     void            CopyImageClipped (UInt32 index, SInt32 top, SInt32 left);
  112.     
  113.     // The actual class makes 8 copies of the tile data, once for each tile alignment.  If you are
  114.     // going to call any of these routines, make sure you call the one for the destination's 
  115.     // alignment.  If you don't call the correct routine, it will probably draw okay, just much
  116.     // slower -- check out the blitter implementation for details.
  117.     void             CopyImageUnclipped0 (UInt32 index, unsigned char *destPtr);
  118.     void             CopyImageUnclipped1 (UInt32 index, unsigned char *destPtr);
  119.     void             CopyImageUnclipped2 (UInt32 index, unsigned char *destPtr);
  120.     void             CopyImageUnclipped3 (UInt32 index, unsigned char *destPtr);
  121.     void             CopyImageUnclipped4 (UInt32 index, unsigned char *destPtr);
  122.     void             CopyImageUnclipped5 (UInt32 index, unsigned char *destPtr);
  123.     void             CopyImageUnclipped6 (UInt32 index, unsigned char *destPtr);
  124.     void             CopyImageUnclipped7 (UInt32 index, unsigned char *destPtr);
  125.                                    
  126.  
  127.  
  128. protected:
  129.     
  130. /*************************************************************************************
  131.     Constructor/Destructor
  132.     
  133.     Because the constructor and destructor should never be called except internally by the class,
  134.     I've made them protected.  You should call the macro functions instead.
  135. *************************************************************************************/
  136.  
  137. /*************************************************************************************
  138.     Data Structures
  139.     
  140.     The actual data used to hold the TTileCollection.  We always align them to power alignment,
  141.     but the alignment is actually the same for 68K alignment anyway....
  142. *************************************************************************************/
  143.  
  144.     TTileCollection (SInt16 resID);
  145.     ~TTileCollection (void);
  146.     
  147.         SInt16            fResID;             // 2 bytes
  148.         UInt16            fReferenceCount;    // 2 bytes, # of owners of this collection;
  149.         UInt32            fNumberOfTiles;        // 4 bytes
  150.         Handle            fTiles;                   // 4 bytes, holds all of the Tile data.
  151.         UInt32            fTileOffset;
  152. };
  153.  
  154. #if PRAGMA_STRUCT_ALIGN
  155. #pragma options align=reset
  156. #endif
  157.  
  158. #endif /* _TTILECOLLECTION_ */